<?php
$post = $_POST;
try {
    $_config = file_get_contents('./config.conf');
    $_config = explode('\n', $_config);
    $config = [];
    foreach ($_config as $key => $value) {
        $_arr = explode('=', $value);
        $config[$_arr[0]] = $_arr[1];
    }
    $host = '';
    $type = $post['listtype'];
    switch ($type) {
        case 'img':
            # 获取图片文件夹列表
            exec('ls ./images', $list);
            $host = $config['img_host'] ?? '';
            break;
        case 'video':
            # 获取视频列表
            exec('ls ./media', $list);
            $host = $config['video_host'] ?? '';
            break;
        case 'email':
            # 获取邮箱图片列表
            exec('ls ./emailimg', $list);
            $host = $config['email_host'] ?? '';
            break;
        default:
            $list = ["类型错误"];
            break;
    }

    echo json_encode([
        'code' => 1, 'msg' => 'success', 'list' => $list, 'host' => $host,
    ]);exit;
} catch (\Throwable $th) {
    echo $th->getMessage();
    var_dump($th->getTraceAsString());
}
exit;